package cn.b.sky.form.form.builder.impl;

import cn.b.sky.form.form.builder.BaseElementBuilder;
import cn.b.sky.form.model.BusinessField;
import cn.b.sky.form.model.ScreenField;
import org.apache.commons.lang3.StringUtils;

public class TextAreaBuilder extends BaseElementBuilder {

  @Override
  public String buildHtmlElement(ScreenField sf) {

    BusinessField field = sf.getBf();
    StringBuilder sb = new StringBuilder("<textarea rows=\"2\" cols=\"70\" id=\"");
    sb.append(field.getFieldLabel()).append("\"");

    if (sf.getReadonlyFlag() == 1) {
      sb.append(" readonly ");
    }
    if (!StringUtils.isBlank(field.getDbField())) {
      sb.append("name=\"").append(field.getDbField()).append("\"");
    }
    //输入框检验
    String validation = this.getValidationAttribute(field);
    if (!StringUtils.isBlank(validation)) {
      sb.append(" class=\"").append(validation).append("\"");
    }
    sb.append(" maxlength=\"").append(field.getLength()).append("\"");
    
    sb.append(">").append(field.getDefaultValue()).append("</textarea>");
    
    return sb.toString();
  }
}
